package DataAccess;

import java.util.*;

/** 
 DataAccessBase ��ժҪ˵����
*/
public abstract class DataAccessBase
{
	public DataAccessBase()
	{
		SQL = new SqlAccess();
		_DataRow = BuildRow();
		_DataRow.Table.Rows.Add(_DataRow);
	}
	public DataAccessBase(DataRow dataRow)
	{
		SQL = new SqlAccess();
		this._DataRow = dataRow;
	}
	public DataAccessBase(DataRowView dataRowView)
	{
		this();
		for (DataColumn column : _DataRow.Table.Columns)
		{
			_DataRow.setItem(column.ColumnName, dataRowView.getItem(column.ColumnName));
		}
	}
	public final void newObject(DataRow dataRow)
	{
		SQL = new SqlAccess();
		this._DataRow = dataRow;
	}
	protected SqlAccess SQL;
	protected DataRow _DataRow;
	protected abstract DataRow BuildRow();
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region Transaction
	protected SqlTransaction Transaction;
	public final boolean BeginTransaction()
	{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if(DEBUG)
		Transaction = SQL.BeginTransaction();
		return true;
//#else
		try
		{
			Transaction = ora.BeginTransaction();
			return true;
		}
		catch (System.Data.OracleClient.OracleException e)
		{
			return false;
		}
//#endif
	}
	public final void Rollback()
	{
		Transaction.Rollback();
	}
	public final void Commit()
	{
		Transaction.Commit();
	}
//		public void AddTransaction(DataAccessBase dataAccess)
//		{
//			dataAccess.Transaction = this.Transaction;
//		}
	public final void ReferenceTransactionFrom(DataAccessBase dataAccess)
	{
		this.Transaction = dataAccess.Transaction;
	}
	protected final int ExecuteSQL(String sql)
	{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if(DEBUG)
		sql = Helper.BeautifulSql(sql);
//#endif
		if (Transaction != null)
		{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if(DEBUG)
			try
			{
				return SQL.ExecuteSQL(sql, Transaction);
			}
			catch (RuntimeException e)
			{
				Transaction.Rollback();
				throw new RuntimeException(e.getMessage());
			}
//#else
			return sql.ExecuteSQL(sql, Transaction);
//#endif

		}
		else
		{
			return SQL.ExecuteSQL(sql);
		}
	}
	protected final DataTable GetDataTable(String sql)
	{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if(DEBUG)
		sql = Helper.BeautifulSql(sql);
//#endif
		if (Transaction != null)
		{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if(DEBUG)
			try
			{
				return SQL.GetDataTable(sql, Transaction);
			}
			catch (RuntimeException e)
			{
				Transaction.Rollback();
				throw new RuntimeException(e.getMessage());
			}
//#else
			return ora.GetDataTable(sql);
//#endif
		}
		else
		{
			return SQL.GetDataTable(sql);
		}
	}
	protected final int GetIntValue(String sql)
	{
		if (Transaction != null)
		{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if(DEBUG)
			try
			{
				return SQL.GetIntValue(sql, Transaction);
			}
			catch (RuntimeException e)
			{
				Transaction.Rollback();
				throw new RuntimeException(e.getMessage());
			}
//#else
			return sql.GetIntValue(sql,Transaction);
//#endif
		}
		else
		{
			return SQL.GetIntValue(sql);
		}
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion Transaction
	protected final String ToSQLParamStr(String str)
	{
		return Helper.ToSQLParamStr(str);
	}
}